var ui_locale = 'zh_CN';
var default_img = 'http://www.baidu.com//favicon.ico';
var urlImg = "http://www.jice360.com/kiner/";
var _config = {
    version: 100,
    lang: "en",
    skins: {
        skin_cloud: {
            style: {},
            csspath: "",
            icon: ""
        },
        skin_local: {
            style: {},
            csspath: "",
            icon: ""
        }
    },
    style: {
        bodyBackground: {
            "background": "-webkit-gradient(linear, 0% 0%, 0% 100%, from(#0866A4), to(#4DA9E8))"
        },
        background: {
            "background-repeat": "no-repeat",
            "background-position": "center",
            "-webkit-background-size": "",
            "-webkit-transform": ""
        }
    },
    skin: "",
    dialBoxNum: 8,
    dialBoxOpacity: 1,
    dialBoxSpacing: 30,
    dialBoxWidth: 214,
    dialBoxHeight: false,
    dialBoxRadius: 16,
    dialBoxPage: 1,
    toolSwitch: false,
    toolsBoxSwitch: false,
    searchSwitch: false,
    calendarSwitch: false,
    ipSwitch: false,
    weatherSwitch: false,
    openSwitch: true,
    targetSwitch: false,
    helpSwitch: true,
    dialBoxTitleSwitch: false,
    appSwitch: true,
    userSwitch: false,
    dialBoxPageSwitcher: true,
    dialBoxCreateBoxSwitch: false,
    hotQueue: ['skins'],
    bookMarksOpenQueue: [],
    oauthid: "",
    oauthData: {},
    curTab: "home",
    searchType: "",
    city: "",
    passwd: "",
    msgid: "0",
    OTime: 0
};

var _configList = {
    zh_CN: {
        lang: "zh_CN",
        dialBoxes: {
            webSite: [
			{
                "title": "谷歌",
                "url": "www.google.com.hk"
            },
            {
                "title": "百度",
                "url": "www.baidu.com"
            },
            {
                "title": "第一财经视频",
                "url": "www.yicai.com/video"
            },
            {
                "title": "CNTV",
                "url": "www.cntv.cn"
            },
            {
                "title": "财新网",
                "url": "www.caixin.com"
            },
            {
                "title": "和讯视频",
                "url": "tv.hexun.com"
            },
            {
                "title": "腾讯视频",
                "url": "v.qq.com"
            },
            {
                "title": "新浪视频",
                "url": "video.sina.com.cn"
            },
            {
                "title": "凤凰视频",
                "url": "v.ifeng.com"
            },
            {
                "title": "腾讯微博",
                "url": "t.qq.com"
            },
            {
                "title": "新浪微博",
                "url": "www.weibo.com"
            },
            {
                "title": "搜狐微博",
                "url": "t.sohu.com"
            },
            {
                "title": "网易微博",
                "url": "t.163.com"
            },
            {
                "title": "涨乐微博",
                "url": "t.zhangle.com"
            },
            {
                "title": "搜牛微博",
                "url": "search.10jqka.com.cn/channel/weibo"
            },
            {
                "title": "和讯微博",
                "url": "t.hexun.com"
            },
            {
                "title": "第一财经",
                "url": "www.yicai.com"
            },
            {
                "title": "和讯网",
                "url": "www.hexun.com"
            },
            {
                "title": "凤凰网",
                "url": "www.ifeng.com"
            },
			{
                "title": "腾讯财经",
                "url": "finance.qq.com"
            },
            {
                "title": "新浪财经",
                "url": "finance.sina.com.cn"
            },
            {
                "title": "搜狐财经",
                "url": "business.sohu.com"
            },
            {
                "title": "网易财经",
                "url": "money.163.com"
            },
            {
                "title": "全景网",
                "url": "www.p5w.net"
            },
            {
                "title": "华尔街日报中文",
                "url": "cn.wsj.com/gb"
            },
			{
                "title": "FT中文",
                "url": "www.ftchinese.com"
            },
            {
                "title": "工商银行",
                "url": "www.icbc.com.cn"
            },
            {
                "title": "建设银行",
                "url": "www.ccb.com"
            },
            {
                "title": "中国银行",
                "url": "www.bank-of-china.com"
            },
            {
                "title": "交通银行",
                "url": "www.bankcomm.com"
            },
            {
                "title": "农业银行",
                "url": "www.abchina.com"
            },
			{
                "title": "招商银行",
                "url": "www.cmbchina.com"
            },
            {
                "title": "中信银行",
                "url": "bank.ecitic.com"
            },
            {
                "title": "浦发银行",
                "url": "www.spdb.com.cn"
            },
            {
                "title": "光大银行",
                "url": "www.cebbank.com"
            },
            {
                "title": "兴业银行",
                "url": "www.cib.com.cn"
            },
			{
                "title": "民生银行",
                "url": "www.cmbc.com.cn"
            },
            {
                "title": "平安银行",
                "url": "bank.pingan.com"
            },
			{
                "title": "支付宝",
                "url": "www.alipay.com"
            },
            {
                "title": "亚马逊",
                "url": "www.amazon.cn"
            },
            {
                "title": "当当网",
                "url": "www.dangdang.com"
            },
            {
                "title": "网上书城",
                "url": "www.99read.com"
            }],
            app: [{
                "id": "webstore",
                "title": getI18nMsg('appChromeWebStore'),
                "url": "https://chrome.google.com/webstore?hl=zh-CN",
                "img": default_img
            }]
        }
    }
};

var favicons = {
    "www.google.com.hk": {
        "rgb": "0,0,255"
    },
    "www.baidu.com": {
        "rgb": "22,105,250"
    },
    "www.yicai.com": {
        "rgb": "243,1,1"
    },
    "www.cntv.cn": {
        "rgb": "244,11,24"
    },
    "www.caixin.com": {
        "rgb": "232,70,8"
    },
    "www.hexun.com": {
        "rgb": "233,153,38"
    },
	"tv.hexun.com": {
        "rgb": "244,142,9"
    },
    "v.qq.com": {
        "rgb": "244,142,9"
    },
    "video.sina.com.cn": {
        "rgb": "0,148,105"
    },
    "v.ifeng.com": {
        "rgb": "191,0,0"
    },
    "t.qq.com": {
        "rgb": "222,77,58"
    },
    "www.weibo.com": {
        "rgb": "232,70,8"
    },
    "t.sohu.com": {
        "rgb": "153,28,28"
    },
    "t.163.com": {
        "rgb": "251,86,0"
    },
    "t.zhangle.com": {
        "rgb": "130,169,13"
    },
    "search.10jqka.com.cn": {
        "rgb": "0,93,172"
    },
	"t.hexun.com": {
        "rgb": "244,142,9"
    },
    "www.ifeng.com": {
        "rgb": "0,148,105"
    },
    "finance.qq.com": {
        "rgb": "191,0,0"
    },
    "finance.sina.com.cn": {
        "rgb": "222,77,58"
    },
    "business.sohu.com": {
        "rgb": "232,70,8"
    },
    "money.163.com": {
        "rgb": "153,28,28"
    },
    "www.p5w.net": {
        "rgb": "251,86,0"
    },
    "cn.wsj.com": {
        "rgb": "130,169,13"
    },
    "www.ftchinese.com": {
        "rgb": "0,93,172"
    },
	"www.icbc.com.cn": {
        "rgb": "244,142,9"
    },
    "www.ccb.com": {
        "rgb": "0,148,105"
    },
    "www.bank-of-china.com": {
        "rgb": "191,0,0"
    },
    "www.bankcomm.com": {
        "rgb": "222,77,58"
    },
    "www.abchina.com": {
        "rgb": "232,70,8"
    },
    "www.cmbchina.com": {
        "rgb": "153,28,28"
    },
    "bank.ecitic.com": {
        "rgb": "251,86,0"
    },
    "www.spdb.com.cn": {
        "rgb": "130,169,13"
    },
    "www.cebbank.com": {
        "rgb": "0,93,172"
    },
	"www.cib.com.cn": {
        "rgb": "244,142,9"
    },
    "www.cmbc.com.cn": {
        "rgb": "0,148,105"
    },
    "bank.pingan.com": {
        "rgb": "191,0,0"
    },
    "www.alipay.com": {
        "rgb": "222,77,58"
    },
    "www.amazon.cn": {
        "rgb": "232,70,8"
    },
    "www.dangdang.com": {
        "rgb": "153,28,28"
    },
    "www.99read.com": {
        "rgb": "251,86,0"
    }
};

var config = _configList[ui_locale];
if (typeof config != 'undefined') {
    $.each(config,function(i, n) {
        _config[i] = n
    })
}


var _screenArrangementList = {
	    "default": {
	        "narrow": {
	            'small': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.1,
	                    'heightBlank': 0.1
	                },
	                '8': {
	                    'cols': 4,
	                    'rows': 2,
	                    'widthBlank': 0.05,
	                    'heightBlank': 0.18
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.1,
	                    'heightBlank': 0.1
	                },
	                '20': {
	                    'cols': 5,
	                    'rows': 4,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.02
	                }
	            },
	            'normal': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.2,
	                    'heightBlank': 0.1
	                },
	                '8': {
	                    'cols': 4,
	                    'rows': 2,
	                    'widthBlank': 0.05,
	                    'heightBlank': 0.22
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.15,
	                    'heightBlank': 0.16
	                },
	                '20': {
	                    'cols': 5,
	                    'rows': 4,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.02
	                }
	            }
	        },
	        "wide": {
	            'small': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.3,
	                    'heightBlank': 0.05
	                },
	                '8': {
	                    'cols': 4,
	                    'rows': 2,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.05
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.15,
	                    'heightBlank': 0.02
	                },
	                '20': {
	                    'cols': 5,
	                    'rows': 4,
	                    'widthBlank': 0.15,
	                    'heightBlank': 0.02
	                }
	            },
	            'normal': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.3,
	                    'heightBlank': 0.1
	                },
	                '8': {
	                    'cols': 4,
	                    'rows': 2,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.1
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.1,
	                    'heightBlank': 0.05
	                },
	                '20': {
	                    'cols': 5,
	                    'rows': 4,
	                    'widthBlank': 0.1,
	                    'heightBlank': 0.05
	                }
	            }
	        }
	    },
	    "square": {
	        "narrow": {
	            'small': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.03
	                },
	                '8': {
	                    'cols': 4,
	                    'rows': 2,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.05
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.02
	                },
	                '15': {
	                    'cols': 5,
	                    'rows': 3,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.08
	                },
	            },
	            'normal': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.05
	                },
	                '8': {
	                    'cols': 4,
	                    'rows': 2,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.15
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.05
	                },
	                '15': {
	                    'cols': 5,
	                    'rows': 3,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.05
	                },
	            }
	        },
	        "wide": {
	            'small': {
	                '4': {
	                    'cols': 4,
	                    'rows': 1,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.28
	                },
	                '8': {
	                    'cols': 4,
	                    'rows': 2,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.04
	                },
	                '15': {
	                    'cols': 5,
	                    'rows': 3,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.08
	                },
	                '21': {
	                    'cols': 7,
	                    'rows': 3,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.08
	                }
	            },
	            'normal': {
	                '4': {
	                    'cols': 4,
	                    'rows': 1,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.32
	                },
	                '8': {
	                    'cols': 4,
	                    'rows': 2,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.05
	                },
	                '15': {
	                    'cols': 5,
	                    'rows': 3,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.08
	                },
	                '21': {
	                    'cols': 7,
	                    'rows': 3,
	                    'widthBlank': 0.03,
	                    'heightBlank': 0.08
	                }
	            }
	        }
	    },
	    "seamless": {
	        "narrow": {
	            'small': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.35,
	                    'heightBlank': 0.2
	                },
	                '9': {
	                    'cols': 3,
	                    'rows': 3,
	                    'widthBlank': 0.35,
	                    'heightBlank': 0.1
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.2,
	                    'heightBlank': 0.15
	                },
	                '24': {
	                    'cols': 6,
	                    'rows': 4,
	                    'widthBlank': 0.1,
	                    'heightBlank': 0.15
	                }
	            },
	            'normal': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.35,
	                    'heightBlank': 0.2
	                },
	                '9': {
	                    'cols': 3,
	                    'rows': 3,
	                    'widthBlank': 0.35,
	                    'heightBlank': 0.1
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.2,
	                    'heightBlank': 0.15
	                },
	                '24': {
	                    'cols': 6,
	                    'rows': 4,
	                    'widthBlank': 0.1,
	                    'heightBlank': 0.15
	                }
	            }
	        },
	        "wide": {
	            'small': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.35,
	                    'heightBlank': 0.2
	                },
	                '8': {
	                    'cols': 4,
	                    'rows': 2,
	                    'widthBlank': 0.15,
	                    'heightBlank': 0.28
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.2,
	                    'heightBlank': 0.06
	                },
	                '24': {
	                    'cols': 6,
	                    'rows': 4,
	                    'widthBlank': 0.1,
	                    'heightBlank': 0.06
	                }
	            },
	            'normal': {
	                '4': {
	                    'cols': 2,
	                    'rows': 2,
	                    'widthBlank': 0.35,
	                    'heightBlank': 0.2
	                },
	                '9': {
	                    'cols': 3,
	                    'rows': 3,
	                    'widthBlank': 0.32,
	                    'heightBlank': 0.1
	                },
	                '12': {
	                    'cols': 4,
	                    'rows': 3,
	                    'widthBlank': 0.2,
	                    'heightBlank': 0.15
	                },
	                '24': {
	                    'cols': 6,
	                    'rows': 4,
	                    'widthBlank': 0.1,
	                    'heightBlank': 0.15
	                }
	            }
	        }
	    }
	};
var screenWidth = window.screen.width, screenHeight = window.screen.height; 
var dialboxSize = screenHeight > 900 ? 'normal': 'small';
var dialboxProportion = (screenWidth / screenHeight) > 1.4 ? 'wide': 'narrow'; 
if (typeof _screenArrangementList['default'][dialboxProportion][dialboxSize][_config['dialBoxNum']] != 'undefined') {
    var _DScreenArrangement = _screenArrangementList['default'][dialboxProportion][dialboxSize][_config['dialBoxNum']];
//    console.log(screenWidth);
//    console.log(_DScreenArrangement['cols']);
//    console.log(_config['dialBoxSpacing']);
//    console.log(_DScreenArrangement['cols']);
//    console.log(_DScreenArrangement['widthBlank']);
//    console.log(_DScreenArrangement['cols']);
   _config['dialBoxWidth'] = parseInt((screenWidth - ((_DScreenArrangement['cols'] + 3) * _config['dialBoxSpacing']) - (_DScreenArrangement['cols'] * 2 * 1) - parseInt(_DScreenArrangement['widthBlank'] * screenWidth)) / _DScreenArrangement['cols']);
   _config['dialBoxHeight'] = parseInt((screenHeight - ((_DScreenArrangement['rows'] + 3) * _config['dialBoxSpacing']) - (_DScreenArrangement['rows'] * 2 * 1) - parseInt(_DScreenArrangement['heightBlank'] * screenHeight) - 246) / _DScreenArrangement['rows'])
} 
	

var user = $.user();
var h5Storage = new $.h5Storage(),
	PDI = $.pdi(),
	myBox,
	oauthBox,
	version = "version",
	ver = _config.version,
	tabID = '',
	serverValue = [],
	protocol = 'chrome',
	setupDialog = '';

$(function() {
    myBox = $('.appDialbox').dialbox({
        num: PDI.get('setup', 'dialBoxNum'),
        page: PDI.get('setup', 'dialBoxPage'),
        opacity: PDI.get('setup', 'dialBoxOpacity'),
        spacing: PDI.get('setup', 'dialBoxSpacing'),
        titleShow: PDI.get('setup', 'dialBoxTitleSwitch'),
        width: PDI.get('setup', 'dialBoxWidth'),
        height: PDI.get('setup', 'dialBoxHeight'),
        radius: PDI.get('setup', 'dialBoxRadius')    
    });
	$("body").css("background-image",PDI.get('setup', 'bgimage'));

	$('.dialBoxNum').bind('click', 
            function() {
                var type = 'default';
                myBox.num = parseInt($(this).text());
                myBox.spacing = myBox.num > 9 ? 15: 30;
                if ($(this).parent().hasClass('default')) {
                    myBox.titleShow = false;
                    myBox.radius = 10
                } else {
                    if ($(this).parent().hasClass('circular')) {
                        myBox.titleShow = true;
                        myBox.radius = 200;
                        type = "square"
                    } else if ($(this).parent().hasClass('square')) {
                        myBox.titleShow = true;
                        myBox.radius = 60;
                        type = "square"
                    } else if ($(this).parent().hasClass('seamless')) {
                        myBox.titleShow = false;
                        myBox.spacing = 0;
                        myBox.radius = 0;
                        type = "seamless"
                    }
                }
                var _screenArrangement = _screenArrangementList[type][dialboxProportion][dialboxSize][myBox.num];
                if (typeof _screenArrangement != 'undefined') {
                    myBox.widthBlank = _screenArrangement['widthBlank'];
                    myBox.heightBlank = _screenArrangement['heightBlank'];
                    myBox.adaptive(_screenArrangement['cols'], _screenArrangement['rows'], type)
                }
                PDI.set('setup', 'dialBoxNum', myBox.num);
                PDI.set('setup', 'dialBoxSpacing', myBox.spacing);
                PDI.set('setup', 'dialBoxWidth', myBox.width);
                PDI.set('setup', 'dialBoxHeight', parseInt(myBox.height - 32));
                PDI.set('setup', 'dialBoxRadius', myBox.radius);
                PDI.set('setup', 'dialBoxTitleSwitch', myBox.titleShow);
                myBox.init()
            });
	
	
	$("#skin > li > a").click(function(){
		$("body").css("background-image",$(this).children("img").attr("skin"));
		PDI.set('setup', "bgimage", $(this).children("img").attr("skin"));
    });
	
	
	$('#dvDockStart').mobilyblocks();
	
	$("#layout").click(function(){
		$(this).css({ "z-index": "12", "width": "420px", "height":"80px" }).children("a").fadeOut(50);;
		$("#setup").children(".topClose").hide().end().fadeIn("slow").children(".topClose").show();
	});
	$("#setup > .topClose").live('click', function() {
		  $("#layout").css({ "z-index": "9", "width": "30px", "height":"24px" }).children("a").fadeIn("slow");;
		  $("#setup").css({'marginTop': '0px'}).hide();
		});
	
    //下面工具栏定位
	$('#navigation').stop().css("left",($(document.body).width()/2)-300);
	$('#navigation span').stop().animate({'marginTop':'-2px'},1000);
	
	//工具栏鼠标效果
	$('#navigation > li').hover(
		function () {
			$('span',$(this)).stop().animate({'marginTop':'-35px'},200).addClass("over").children("a").css("color","#ff5500");
		},
		function () {
			$('span',$(this)).stop().animate({'marginTop':'-2px'},200).removeClass("over").children("a").css("color","#0066cc");
		}
	);
});

//判断浏览器窗口大小
$(window).resize(function() {
	var width = $(this).width();
	$('#navigation').stop().css("left",($(document.body).width()/2)-300);
	if(width<600){$('#navigation').hide()}else{$('#navigation').show()}
});